﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SaludOcupacional.Controller;
using SaludOcupacional.Model;

namespace SaludOcupacional
{
    /// <summary>
    /// Interaction logic for ChangePassword.xaml
    /// </summary>
    public partial class ChangePassword : Window
    {
        private string login;
        private Usuario usuario;
        public ChangePassword(string theLogin)
        {
            InitializeComponent();
            login = theLogin;
            usuario = LoginManager.GetUserByUserName(login);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if( xNewPassword.Password == xReNewPassword.Password)
            {
                if(usuario.Password == xPassword.Password)
                {
                    UsuariosManager.ChangePassword(login,xNewPassword.Password);
                    MessageBox.Show("CAMBIO REALIZADO CON EXITO!!");
                    Close();
                }
                else
                {
                    MessageBox.Show("Error: " +"Password Invalido!");
                    xNewPassword.Password = "";
                    xReNewPassword.Password = "";
                    xPassword.Password = "";

                }
            }
            else
            {
                MessageBox.Show("Error: " + "Verifique El Nuevo Password!");
                xNewPassword.Password = "";
                xReNewPassword.Password = "";
                xPassword.Password = "";
            }

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void xPassword_PasswordChanged(object sender, RoutedEventArgs e)
        {

        }
    }
}
